<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of View
 *
 * @author Loug S
 */
class View {
    
    /**
     * Notre tableau de données provenant de la vue
     */
    private $data;
    /**
* Fonction principale pour l'affichage "standard"
* @return void
* @param $data Array
     * 
     */
    
    public function render($data, $params, $base, $template) {
        $this->data = $data;
         
        $template = "./".$template . '.tpl';
        if (!file_exists($template)) {
            throw new Exception('Fichier template ' . $template . ' introuvable');
        }
        ob_start();
        require_once $template;
        $content = ob_get_contents();
        ob_end_clean();
        if ($base != null) {
            $base = ''. $base . '.tpl.php';
            if (!file_exists($base)) {
                throw new Exception('Fichier base ' . $base . ' introuvable');
            }
            $this->layout_content = $content;
            ob_start();
            require_once $base;
            $content = ob_get_contents();
            ob_end_clean();
        }
        echo $content;
    }

    /**
     * Un Getter
     * Il sera utilisé dans le fichier de template
     */
    protected function __get($key) {
        if (isset($this->data[$key])) {
            return $this->data[$key];
        }
        return null;
    }

    protected function __isset($key) {
        return isset($this->data[$key]);
    }
}

?>
